﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ShaboForm
{
    public partial class WorkerRegistry : Form
    {
        public WorkerRegistry()
        {
            InitializeComponent();
            this.FormClosing += button1_Click;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string id = textBoxID.Text;
                string fn = textBoxFirstName.Text;
                string ln = textBoxLastName.Text;
                string add = textBoxCity.Text;
                string st = textBoxStreet.Text;
                string hn = textBoxHouseNumber.Text;
                string ct = textBoxCity.Text;
                string pn = textBoxPhoneNumber.Text;
                string jb = comboBox1.Text;
                string pr = "";
                if (jb.Equals("מנהל ראשי"))
                    pr = "0";
                else if (jb.Equals("מנהל סניף"))
                    pr = "1";
                else if (jb.Equals("מנהל מחסן"))
                    pr = "2";
                else if (jb.Equals("אחראי משמרת"))
                    pr = "3";
                else if (jb.Equals("עובד שטח"))
                    pr = "4";
                else if (jb.Equals("מזכירה"))
                    pr = "5";
                else if (jb.Equals("מחסנאי"))
                    pr = "6";
                else if (jb.Equals("שליח"))
                    pr = "7";
                else
                    throw new Exception("job is not included");
                DataAccessLayer.AddWorker(id, fn, ln, jb, st, hn, ct, pn, pr);
                textBoxID.Text = textBoxFirstName.Text = textBoxLastName.Text = comboBox1.Text = textBoxCity.Text=textBoxHouseNumber.Text =
                    textBoxPhoneNumber.Text= textBoxStreet.Text="";
                MessageBox.Show("Worker has been successfully added to the database");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Dispose();
            AdminisrationsForm aForm = new AdminisrationsForm();
            aForm.Show();
        }

        private void WorkerRegistry_Load(object sender, EventArgs e)
        {
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }
    }
}
